package com.多线程07.demo03;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class MyCallable01 implements Callable<String> {
    public String call() throws Exception {

        for (int i=0;i<100;i++){
            System.out.println("家辉向第"+i+"个女孩表白");
        }
        return "答应";
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //1 创建callable
        MyCallable01 myCallable01 = new MyCallable01();
        //2 创建FutureTask封装callbale
        FutureTask<String> ft = new FutureTask<String>(myCallable01);
        //3 创建线程封装FutureTask
        Thread thread = new Thread(ft);
        //4 执行
        thread.start();
        //5 打印返回结果
        String result = ft.get();
        System.out.println(result);

    }


}
